<template>
  <div class="my-tag">
    <input
      class="input"
      type="text"
      placeholder="输入标签"
      v-if='isShow'
      v-focus
      @blur='isShow = false'
      v-model="inputTag"
      @keydown.enter='changeTag'
    />
    <div @dblclick="show" v-else class="text">{{value}}</div>
  </div>
</template>

<script>
export default {
  props:{
    value:{
      type:String,
      require:true
    }
  },
  data() {
    return {
      isShow:false,
      inputTag:''
    }
  },
  methods:{
    show() {
      this.isShow = true
      this.inputTag = this.value
    },
    changeTag() {
      this.isShow = false
      this.$emit('input',this.inputTag)
    }
  }
}
</script>

<style lang='less' scope>
  .my-tag {
  cursor: pointer;
  .input {
    appearance: none;
    outline: none;
    border: 1px solid #ccc;
    width: 100px;
    height: 40px;
    box-sizing: border-box;
    padding: 10px;
    color: #666;
    &::placeholder {
      color: #666;
    }
  }
}
</style>